/**
 * 交通工具管理初始化
 */
var Official = {
    id: "OfficialTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Official.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '关键字', field: 'keyword', align: 'center', valign: 'middle', sortable: true},
        {title: '内容', field: 'content', align: 'center', valign: 'middle', sortable: true},
        {title: '类型', field: 'type', align: 'center', valign: 'middle', sortable: true},
        {title: '时间', field: 'time', align: 'center', valign: 'middle', sortable: true}];
};

Official.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Official.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Official.openAddOfficial = function () {
    var index = layer.open({
        type: 2,
        title: '添加交通工具',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/official/Official_add'
    });
    this.layerIndex = index;
};

/**
 * 公众号详情
 */
Official.openOfficialDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '公众号详情',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/official/Official_update/' + Official.seItem.id
        });
        this.layerIndex = index;
    }
};

Official.initialReplySettings = function () {//初始回复设置
    var index = layer.open({
        type: 2,
        title: '初始回复设置 ',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/official/to_initialReplySettings'
    });
    this.layerIndex = index;
};

Official.sendingGroup = function () {//初始回复设置
    var index = layer.open({
        type: 2,
        title: '微信公众号群发文本消息',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/official/to_sendingGroup'
    });
    this.layerIndex = index;
};

/**
 * 删除部门
 */
Official.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/official/delete/" + this.seItem.id, function (data) {
            Feng.success("删除成功!");
            Official.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Official.formParams = function () {
    var queryData = {};
    queryData['keyword'] = $("#keyword").val();
    return queryData;
}
Official.resetSearch = function () {
    $("#keyword").val("");
    Official.search();
};
/**
 * 查询列表
 */
Official.search = function () {
    Official.table.refresh({query: Official.formParams()});
};

$(function () {
    var defaultColunms = Official.initColumn();
    var table = new BSTable(Official.id, "/official/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Official.formParams());
    Official.table = table.init();
    Official.table = table;
});
